/* COMMON FUNCTION USING IN layout_111 AND OTHER LAYOUT PAGE */
var LOADING_STATUS_COUNT = 0;
var SHOUT_BOX_UPDATE_INTERVAL = 500000;
var LOAD_POSTS_UPDATE_INTERVAL = 500000;
var RECENT_POSTS_UPDATE_INTERVAL = 500000;
var MOST_VIEW_POSTS_UPDATE_INTERVAL = 600000;
var WHOONLINE_UPDATE_INTERVAL = 60000;
var WHONEW_UPDATE_INTERVAL = 43200;
var shoutBox;
loadToElement(base_url+'user/user/box', null, 'infobox', null, true, null);

function loadAvatar(url, holderId, maxWidth, maxHeight) {
	loadToElement(url, null, holderId, "maxwidth="+maxWidth+"&maxheight="+maxHeight, false);
}

function loadToElement(url ,formID, recieveAreaID, additionalPostString, showLoading, property) {
	var parameters = (additionalPostString==null)?"":additionalPostString;
	if (formID != null) {
		var form = $(formID);
		if (form != null)
			if (parameters == "") 
				parameters = form.serialize(false);
			else parameters += "&"+form.serialize(false);
	}
	if (showLoading) increaseStatusCount();
	new Ajax.Request(url,
		{ method: 'post', 
			onSuccess: function(transport){
				if (showLoading) decreaseStatusCount();
				if (recieveAreaID) {
					if (recieveAreaID.length) $(recieveAreaID).update(transport.responseText);
					else if (recieveAreaID.nodeName) recieveAreaID.update(transport.responseText);
				}
				if (property && property.onSuccess) property.onSuccess.call(null, transport);
			},
			onFailure: function(transport){
				if (showLoading) decreaseStatusCount();
				if (property && property.onFailure) property.onFailure.call(null, transport);
			},
			parameters: parameters
		});
}

/**************** STATUS ************************************/
function repositionStatus() {
	var e = $('statusline');
	var left = document.all?e.offsetParent.scrollLeft:window.pageXOffset;
	var top = document.all?e.offsetParent.scrollTop:window.pageYOffset;

	var iW = document.all?document.documentElement.clientWidth:window.innerWidth;
	var iH = document.all?document.documentElement.clientHeight:window.innerHeight;

	left = left+iW/2-e.offsetWidth/2;
	top = top+iH/2-e.offsetHeight/2;

	e.style.left = left+"px";
	e.style.top = top+"px";
}

function showStatus(str) {
	var e = $('statusline');
	if (e) {
		e.innerHTML = str;		
		if (e.style.display == "none")
			window.onscroll = function() {
				repositionStatus();
			};
			
		e.style.display = 'block';
		repositionStatus();
	}
}

function hideStatus() {
	var e = $('statusline');
		if (e) {
		e.innerHTML = "";
		e.style.display = 'none';
		window.onscroll = '';
	}
}

function increaseStatusCount(str) {
	LOADING_STATUS_COUNT++;
	if (str) showStatus(str);
	else showStatus("Loading....");
	
	//if (LOADING_STATUS_COUNT >= 1) showBlocker();
}
	
function decreaseStatusCount() {
	
	LOADING_STATUS_COUNT--;
	if (LOADING_STATUS_COUNT <= 0) {
		hideStatus();
		//hideBlocker();
		LOADING_STATUS_COUNT = 0;
	}
}